
from itsdangerous import TimedJSONWebSignatureSerializer as TJWSS

from django.conf import settings

def generate_sign_openid(openid):
    serializer = TJWSS(secret_key=settings.SECRET_KEY,expires_in=300)

    sign_openid = serializer.dumps({"openid" : openid})

    return sign_openid.decode()


def decode_sign_openid(sign_openid):
    serializer = TJWSS(secret_key=settings.SECRET_KEY, expires_in=300)

    try:

        dict_data = serializer.loads(sign_openid)
    except Exception as e :
        return None

    return dict_data.get('openid')
